package com.ehelper.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ehelper.DAO.IssueDAO;
import com.ehelper.model.Issue;

@Component("issueService")
public class IssueService {
	private IssueDAO issueDAO;

	public IssueDAO getIssueDAO() {
		return issueDAO;
	}

	@Resource(name="issueDAO")
	public void setIssueDAO(IssueDAO issueDAO) {
		this.issueDAO = issueDAO;
	}
	
	public String addIssueService(Issue issue)
	{
		String message;
		issue.setTag(0);
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
    	String today=sdf.format(date);
		try {
			Date tDate=sdf.parse(today);
			issue.setSubmitDate(tDate);
			message=issueDAO.addIssue(issue);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			message="noadd";
		}
		return message;
	}

	public List<Issue> findAllIssues() {
		return issueDAO.findIssues();
	}

	public void deleteById(Integer id) {
		issueDAO.deleteIssueById(id);
	}

	public void passIssueById(Integer id) {
		issueDAO.passIssueById(id);
	}
}
